//package com.example.pets.model.datasource.DataSourceImpl;
//
//
//import androidx.lifecycle.LiveData;
//import androidx.lifecycle.MutableLiveData;
//
//import com.example.pets.model.datasource.LostDataSource;
//import com.example.pets.model.entities.Lost;
//import com.google.firebase.firestore.CollectionReference;
//import com.google.firebase.firestore.DocumentReference;
//import com.google.firebase.firestore.FirebaseFirestore;
//import com.google.firebase.firestore.QueryDocumentSnapshot;
//
//import java.util.ArrayList;
//import java.util.List;
//
//public class LostDataSourceImpl implements LostDataSource {
//
//    private final CollectionReference lostCollection;
//
//    public LostDataSourceImpl() {
//        FirebaseFirestore db = FirebaseFirestore.getInstance();
//        lostCollection = db.collection("lostReports");
//    }
//
//    @Override
//    public LiveData<Lost> getLostById(String lid) {
//        MutableLiveData<Lost> lostLiveData = new MutableLiveData<>();
//        lostCollection.document(lid)
//                .addSnapshotListener((snapshot, error) -> {
//                    if (error != null || snapshot == null || !snapshot.exists()) {
//                        lostLiveData.setValue(null);
//                        return;
//                    }
//                    Lost lost = snapshot.toObject(Lost.class);
//                    lostLiveData.setValue(lost);
//                });
//        return lostLiveData;
//    }
//
//    @Override
//    public LiveData<Boolean> addLost(Lost lost) {
//        MutableLiveData<Boolean> resultLiveData = new MutableLiveData<>();
//        lostCollection.add(lost)
//                .addOnSuccessListener(documentReference -> resultLiveData.setValue(true))
//                .addOnFailureListener(e -> resultLiveData.setValue(false));
//        return resultLiveData;
//    }
//
//    @Override
//    public LiveData<Boolean> updateLost(String lid, Lost lost) {
//        MutableLiveData<Boolean> resultLiveData = new MutableLiveData<>();
//        lostCollection.document(lid)
//                .set(lost)
//                .addOnSuccessListener(aVoid -> resultLiveData.setValue(true))
//                .addOnFailureListener(e -> resultLiveData.setValue(false));
//        return resultLiveData;
//    }
//
//    @Override
//    public LiveData<Boolean> deleteLost(String lid) {
//        MutableLiveData<Boolean> resultLiveData = new MutableLiveData<>();
//        lostCollection.document(lid)
//                .delete()
//                .addOnSuccessListener(aVoid -> resultLiveData.setValue(true))
//                .addOnFailureListener(e -> resultLiveData.setValue(false));
//        return resultLiveData;
//    }
//
//    @Override
//    public LiveData<List<Lost>> getLostByUser(DocumentReference userRef) {
//        MutableLiveData<List<Lost>> listLiveData = new MutableLiveData<>();
//        lostCollection.whereEqualTo("user", userRef)
//                .addSnapshotListener((querySnapshot, error) -> {
//                    if (error != null || querySnapshot == null) {
//                        listLiveData.setValue(null);
//                        return;
//                    }
//                    List<Lost> lostList = new ArrayList<>();
//                    for (QueryDocumentSnapshot doc : querySnapshot) {
//                        Lost lost = doc.toObject(Lost.class);
//                        lostList.add(lost);
//                    }
//                    listLiveData.setValue(lostList);
//                });
//        return listLiveData;
//    }
//
//    @Override
//    public LiveData<List<Lost>> getAllLostReports() {
//        MutableLiveData<List<Lost>> listLiveData = new MutableLiveData<>();
//        lostCollection.addSnapshotListener((querySnapshot, error) -> {
//            if (error != null || querySnapshot == null) {
//                listLiveData.setValue(null);
//                return;
//            }
//            List<Lost> lostList = new ArrayList<>();
//            for (QueryDocumentSnapshot doc : querySnapshot) {
//                Lost lost = doc.toObject(Lost.class);
//                lostList.add(lost);
//            }
//            listLiveData.setValue(lostList);
//        });
//        return listLiveData;
//    }
//}
